home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / gnustuff / tos / progut~1 / gperf.zoo / src / bool-array.cc next >
Encoding:
C/C++ Source or Header  |  1991-09-25  |  2.6 KB  |  96 lines

  1. /* Fast lookup table abstraction implemented as an Iteration Number Array
  2.    Copyright (C) 1989 Free Software Foundation, Inc.
  3.    written by Douglas C. Schmidt (schmidt@ics.uci.edu)
  4.  
  5. This file is part of GNU GPERF.
  6.  
  7. GNU GPERF is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 1, or (at your option)
  10. any later version.
  11.  
  12. GNU GPERF is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with GNU GPERF; see the file COPYING.  If not, write to
  19. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  20.  
  21. #include <stdio.h>
  22. #include "options.h"
  23. #include "bool-array.h"
  24.  
  25. /* Prints out debugging diagnostics. */
  26.  
  27. Bool_Array::~Bool_Array (void) 
  28. {
  29.   T (Trace t ("Bool_Array::~Bool_Array");)
  30.   if (option[DEBUG])
  31.     fprintf (stderr, "\ndumping boolean array information\n"
  32.              "size = %d\niteration number = %d\nend of array dump\n",
  33.              size, iteration_number);
  34. }
  35.  
  36. #ifndef __OPTIMIZE__
  37.  
  38. Bool_Array::Bool_Array (void)
  39. {
  40.   T (Trace t ("Bool_Array::Bool_Array");)
  41.   storage_array = 0;
  42.   iteration_number = size = 0;
  43. }
  44.  
  45. void
  46. Bool_Array::init (STORAGE_TYPE *buffer, STORAGE_TYPE s)
  47. {
  48.   T (Trace t ("Bool_Array::init");)
  49.   size             = s;
  50.   iteration_number = 1;
  51.   storage_array    = buffer;
  52.   bzero (storage_array, s * sizeof *storage_array);
  53.   if (option[DEBUG])
  54.     fprintf (stderr, "\nbool array size = %d, total bytes = %d\n",
  55.              size, size * sizeof *storage_array);
  56. }
  57.  
  58. int  
  59. Bool_Array::find (int index) 
  60. {
  61.   T (Trace t ("Bool_Array::find");)
  62.   if (storage_array[index] == iteration_number)
  63.     return 1;
  64.   else
  65.     {
  66.       storage_array[index] = iteration_number;
  67.       return 0;
  68.     }
  69. }
  70.  
  71. void 
  72. Bool_Array::reset (void)  
  73. {
  74.   T (Trace t ("Bool_Array::reset");)
  75.   /* If we wrap around it's time to zero things out again!  However, this only
  76.      occurs once about every 2^31 or 2^15 iterations, so it should probably
  77.      never happen! */
  78.  
  79.   if (++iteration_number == 0)
  80.     {
  81.       if (option[DEBUG])
  82.         {
  83.           fprintf (stderr, "(re-initializing bool_array)...");
  84.           fflush (stderr);
  85.         }
  86.       iteration_number = 1;
  87.       bzero (storage_array, size * sizeof *storage_array);
  88.       if (option[DEBUG])
  89.         {
  90.           fprintf (stderr, "done\n");
  91.           fflush (stderr);
  92.         }
  93.     }
  94. }
  95. #endif /* not defined __OPTIMIZE__ */
  96.